import { ApiCall } from "tsrpc";
import { ReqRename, ResRename } from "../../../../shared/master/body/skill/PtlRename";
import { player } from "../../../../model/fight/body/player";
import { template } from "../../../../shared/master/MsgAction";
import god from "../../../../god";
import app from "../../../../app";

export default async function (call: ApiCall<ReqRename, ResRename>) {
    call.succ({})
    let user = call.req._player as player;
    const name = call.req.name;
    const sks = user.getAllSkills()
    const idx = call.req.idx;
    const changeSk = sks[idx - 1];
    if(!changeSk){
        user.sendMsg(template.default,`没有找到ID为${idx - 1}的技能`)
        return;
    }
    changeSk.rename = name;
    // changeSk.icon = call.req.url;
    // TODO:图片地址修改
    const style_num = Number(god.getServerCfgItem('skill_styleCont').a);
    changeSk.icon_img = `../../resources/img/skill/style/${app.random(1,style_num)}.jpg`
    user.sendMsg(template.skill_info,changeSk.get_panel())
}